/**
 * 初始化详情对话框
 */
var FoodsIngredientInfoDlg = {
    foodsIngredientInfoData : {}
};

/**
 * 清除数据
 */
FoodsIngredientInfoDlg.clearData = function() {
    this.foodsIngredientInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
FoodsIngredientInfoDlg.set = function(key, val) {
    this.foodsIngredientInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
FoodsIngredientInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
FoodsIngredientInfoDlg.close = function() {
    parent.layer.close(window.parent.FoodsIngredient.layerIndex);
}

/**
 * 收集数据
 */
FoodsIngredientInfoDlg.collectData = function() {
    this
    .set('id')
    .set('foodId')
    .set('calory')
    .set('carbohydrate')
    .set('cholesterol')
    .set('copper')
    .set('fat')
    .set('fiberDietary')
    .set('iodine')
    .set('iron')
    .set('kalium')
    .set('lactoflavin')
    .set('magnesium')
    .set('manganese')
    .set('natrium')
    .set('niacin')
    .set('protein')
    .set('selenium')
    .set('thiamine')
    .set('vitaminA')
    .set('vitaminB')
    .set('vitaminC')
    .set('vitaminE')
    .set('zinc')
    .set('calcium')
    .set('phosphor')
    .set('createBy')
    .set('createDate')
    .set('updateBy')
    .set('updateDate')
    .set('delFlag')
    ;
}

/**
 * 提交添加
 */
FoodsIngredientInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/foodsIngredient/add", function(data){
        Feng.success("添加成功!");
        window.parent.FoodsIngredient.table.refresh();
        FoodsIngredientInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.foodsIngredientInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
FoodsIngredientInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/foodsIngredient/update", function(data){
        Feng.success("修改成功!");
        window.parent.FoodsIngredient.table.refresh();
        FoodsIngredientInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.foodsIngredientInfoData);
    ajax.start();
}

$(function() {

});
